#include "StdAfx.h"
#include "Command.h"
#include "SerialSingleton.h"
#include "../macro.h"

Command::Command(const char* command, int delaytime_after, int delaytime_before)
: m_command(command)
, m_delaytime_after(delaytime_after)
, m_delaytime_before(delaytime_before)
{
}

Command::~Command(void)
{
}

bool Command::run(void* param)
{
	DBG_PRINTF("%s\r\n",__FUNCTION__);
	MSG_PRINTF("      [Command] > \"%s\" delaytime_after:%d ms   delaytime_before:%d ms\r\n", m_command.c_str(), m_delaytime_after, m_delaytime_before);
	
	Sleep(m_delaytime_before);

	if (SerialSingleton::getInstance().write(m_command.c_str(), m_command.size()) != m_command.size())
	{
		return false;
	}

	// write return
	if (SerialSingleton::getInstance().write("\n", 1) != 1)
	{
		return false;
	}


	Sleep(m_delaytime_after);

	return true;
}